
#include "AboutDialog.h"

AboutDialog::AboutDialog(void)
{
}

AboutDialog::~AboutDialog(void)
{
}

void AboutDialog::show() const
{
    using std::cout;
    using std::endl;
    using std::ends;

    system("cls");
    cout << "About\n"
         << "\n"
         << "Hey, I'm the programmer of this tricky.\n"
         << "\n"
         << "  This MatrixLife is based on the Life\n"
         << "and Cellular Automata. This version uses\n"
         << "the rule of Conway's Life. That is, life\n"
         << "in a cell will be kept if it has two or\n"
         << "three neighbors with lives, or be generated\n"
         << "if it has three such neighbors. But if\n"
         << "there're too many lives around it, it will\n"
         << "die due to lack of food.\n"
         << "\n"
         << "  If you want the source code, you can\n"
         << "send a email to lavaxin@gmail.com with\n"
         << "subject: \"Source Code: MatrixLife\".\n"
         << "\n"
         << "  You'd better run it in the maximum command\n"
         << "window."
         << "\n"
         << "  Good luck & enjoy yourself!\n"
         << "\n"
         << "Enter \"q\" to main menu."
         << endl;
}

bool AboutDialog::fire()
{
    U_MESSAGE msg(MessageArray::Instance()->getMessage());
    switch (msg)
    {
    case SHOW_ABOUTDLG:
        setFocus(true);
        show();
        return true;
        break;
    default:
        if (getFocus())
        {
            keyboardListener(static_cast<char>(msg));
            return true;
        }
        break;
    }
    return false;
}

void AboutDialog::keyboardListener(char const& key)
{
    setFocus(false);
    switch (key)
    {
    case 'Q':
    case 'q':
        MessageArray::Instance()->postMessage(SHOW_MAINMENU);
        break;
    default:
        std::cout << "Command not found." << std::endl;
        break;
    }
}
